package main

import (
	"fmt"
	"sync"
)

func main() {
	m := sync.Map{}
	wg := sync.WaitGroup{}

	for i := 0; i < 20; i++ {
		wg.Add(1)
		go func(n int) {
			defer wg.Done()
			m.Store(n, n+1)
			fmt.Print(n, "->")
			fmt.Println(m.Load(n))
		}(i)
	}
	wg.Wait()
	fmt.Println("---------------")
	// delete key
	m.Delete(20)

	// range
	m.Range(func(k, v interface{}) bool {
		fmt.Printf("m[%v] = %v\n", k, v)
		return true
	})

}
